package com.foreveross.taskservice.infra.util;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
public class ClassLoadUtils {
	private static URLClassLoader CLASS_LOADER = null;

    public static void add(String s) throws IOException, NoSuchMethodException,
            IllegalAccessException, InvocationTargetException {
        add(new File(s));
    }
    public static void add(File f) throws IOException, NoSuchMethodException,
    	IllegalAccessException, InvocationTargetException {
        f = f.isDirectory() ? f : f.getParentFile();
        add(f.toURI().toURL());
    }

	public static void add(URL url) throws IOException, NoSuchMethodException,
    	IllegalAccessException, InvocationTargetException {
    	getClassLoader(url);
    }
    public static URLClassLoader getClassLoader(URL url) {
    	if(url != null){
    		CLASS_LOADER = new URLClassLoader(new URL[]{url},Thread.currentThread().getContextClassLoader());
    	}
        return CLASS_LOADER;
    }
    
}
